package com.tedu.review.test;

import java.util.Objects;

/**
 * Object类 equal方法:比较两个对象是否相等
 * 两个China类,比较两个China类是否相等[返回值:Boolean]
 * 语法:引用1.equal(引用2)
 */
class China{
    public String city;
    public String county;
    //判断两个中国：城市以及县是否相等【自己决定逻辑】
      public boolean equals(Object o) {
           //1.参数【Object】强转为China对象【引用】
        China china=(China)o;
         //2.判断市与市，县与县是否相等[比较属性：对比实际值]
        boolean c=this.city.equals(china.city);
        boolean y=this.county.equals(china.county);
         //3.返回值：弹出
        return c&&y;
    }
    public int hashCode() {
         return Objects.hash(city, county);
    }
}

public class 对象对比 {
    public static void main(String[] args) {
         China c1=new China();
         System.out.println(c1.toString());
         China c2=new China();
         System.out.println(c2.toString());
         System.out.println(c1.equals(c2));//false
    }
}
